<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">

          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <a-form-item label="订单号">
              <a-input placeholder="请输入订单号" v-model="queryParam.orderNo"></a-input>
            </a-form-item>
          </a-col>
          <template v-if="toggleSearchStatus">
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="商品名称">
                <a-input placeholder="请输入商品名称" v-model="queryParam.spuName"></a-input>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="评价星级">
                <a-select :default-value="null" v-model="queryParam.stars" @change="searchQuery">
                  <a-select-option :value="null">
                    全部
                  </a-select-option>
                  <a-select-option :value="0">
                    0星
                  </a-select-option>
                  <a-select-option :value="1">
                    1星
                  </a-select-option>
                  <a-select-option :value="2">
                    2星
                  </a-select-option>
                  <a-select-option :value="3">
                    3星
                  </a-select-option>
                  <a-select-option :value="4">
                    4星
                  </a-select-option>
                  <a-select-option :value="5">
                    5星
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="有图">
                <a-select :default-value="null" v-model="queryParam.flag" @change="searchQuery">
                  <a-select-option :value="null">
                    全部
                  </a-select-option>
                  <a-select-option :value="0">
                    无图
                  </a-select-option>
                  <a-select-option :value="1">
                    有图
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="是否回复">
                <a-select :default-value="null" v-model="queryParam.isBack" @change="searchQuery">
                  <a-select-option :value="null">
                    全部
                  </a-select-option>
                  <a-select-option :value="0">
                    未回复
                  </a-select-option>
                  <a-select-option :value="1">
                    已回复
                  </a-select-option>
                </a-select>
              </a-form-item>
            </a-col>
            <a-col :xl="6" :lg="7" :md="8" :sm="24">
              <a-form-item label="评论时间">
                <a-range-picker format="YYYY-MM-DD" :placeholder="['开始时间', '结束时间']" @change="onDateChange" />
              </a-form-item>
            </a-col>
          </template>
          <a-col :xl="6" :lg="7" :md="8" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
              <a @click="handleToggleSearch" style="margin-left: 8px">
                {{ toggleSearchStatus ? '收起' : '展开' }}
                <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
              </a>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
<!--    <div class="table-operator">
      <a-upload name="file" :showUploadList="false" :multiple="false" :headers="tokenHeader" :action="importExcelUrl" @change="handleImportExcel">
        <a-button type="primary" icon="import">按模板生成评论</a-button>
      </a-upload>
    </div>-->
    <!-- table区域-begin -->
    <div>

      <a-table ref="table" size="middle" :scroll="{x:true}" bordered rowKey="id" :columns="columns" :dataSource="dataSource" :pagination="ipagination"
        :loading="loading" class="j-table-force-nowrap"
        @change="handleTableChange">

        <template slot="htmlSlot" slot-scope="text">
          <div v-html="text"></div>
        </template>
        <template slot="imgSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无图片</span>
          <img v-else :src="getImgView(text)" height="55px" alt="" style="max-width:80px;font-size: 12px;font-style: italic;" />
        </template>
        <template slot="comment" slot-scope="text,record">
          <div style="font-size:14px;color:#333333;">买家：{{record.nickname}}<br />
            <a-rate disabled v-model="record.stars" />
          </div>
          <div style="font-size:12px;color:#888888;">{{record.createTime}}</div>
          <div>{{record.comment}}</div>
          <div>
            <img v-for="(item,index) in record.imgUrlsObj" :key="index" @click="openUrlView(item)" style="width:40px;margin-right:3px;" :src="item">
          </div>
        </template>
        <template slot="shopComment" slot-scope="text,record">
          <div v-if="record.shopComment">
            <div style="font-size:14px;">{{record.shopComment}}</div>
            <div style="font-size:12px;color:#888888;">{{record.answerTime}}</div>
          </div>
        </template>

        <template slot="fileSlot" slot-scope="text">
          <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
          <a-button v-else :ghost="true" type="primary" icon="download" size="small" @click="downloadFile(text)">
            下载
          </a-button>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit1(record)" v-if="record.shopComment==null||record.shopComment==''">回复</a>
          <a @click="handleEdit2(record)" v-if="record.shopComment!=null&&record.shopComment!=''">删除回复</a>
          <a-divider type="vertical" />
          <a @click="handleEdit3(record)" v-if="record.status==0">显示</a>
          <a @click="handleEdit4(record)" v-if="record.status==1">隐藏</a>
          <a-divider type="vertical" />

          <a-dropdown>
            <a class="ant-dropdown-link">更多
              <a-icon type="down" />
            </a>
            <a-menu slot="overlay">
              <a-menu-item>
                <a-popconfirm title="确定删除吗?" @confirm="() => handleDelete(record.id)">
                  <a>删除</a>
                </a-popconfirm>
              </a-menu-item>
            </a-menu>
          </a-dropdown>
        </span>

      </a-table>
    </div>

    <gms-comment-modal ref="modalForm" @ok="modalFormOk"></gms-comment-modal>
  </a-card>
</template>

<script>
import { putAction } from '@/api/manage'
import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import GmsCommentModal from './modules/GmsCommentModal'
import JDate from '@/components/jeecg/JDate.vue'

export default {
  name: 'GmsCommentList',
  mixins: [JeecgListMixin, mixinDevice],
  components: {
    JDate,
    GmsCommentModal
  },
  data () {
    return {
      description: '评价查询管理页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: "center",
          customRender: function (t, r, index) {
            return parseInt(index) + 1
          }
        },
        // {
        //   title: '用户号',
        //   align: "center",
        //   dataIndex: 'uid'
        // },
        // {
        //   title: '店铺id',
        //   align: "center",
        //   dataIndex: 'shopId'
        // },
        // {
        //   title: '商品编码',
        //   align: "center",
        //   dataIndex: 'itemCode'
        // },
        {
          title: '商品信息',
          align: "left",
          dataIndex: 'spuName'
        },
        // {
        //   title: '规格名称',
        //   align: "center",
        //   dataIndex: 'skuName'
        // },
        {
          title: '订单号',
          align: "center",
          dataIndex: 'orderNo'
        },


        {
          title: '评价内容',
          align: "left",
          dataIndex: 'stars',
          scopedSlots: { customRender: 'comment' }
        },
        // {
        //   title: '评论内容',
        //   align: "center",
        //   dataIndex: 'comment'
        // },
        // {
        //   title: '0:无图,1:有图',
        //   align: "center",
        //   dataIndex: 'flag'
        // },
        // {
        //   title: '图片链接以逗号连接，最多9张',
        //   align: "center",
        //   dataIndex: 'imgUrls',
        //   scopedSlots: { customRender: 'imgSlot' }
        // },
        {
          title: '卖家回复',
          align: "left",
          dataIndex: 'shopComment',
          scopedSlots: { customRender: 'shopComment' }
        },
        // {
        //   title: '回复时间',
        //   align: "center",
        //   dataIndex: 'answerTime',
        //   customRender: function (text) {
        //     return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
        //   }
        // },

        {
          title: '操作',
          dataIndex: 'action',
          align: "center",
          width: 150,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: "/mallBase/gmsComment/list",
        delete: "/mallBase/gmsComment/delete",
        deleteBatch: "/mallBase/gmsComment/deleteBatch",
        exportXlsUrl: "/mallBase/gmsComment/exportXls",
        importExcelUrl: "mallBase/gmsComment/importExcel",

      },
      dictOptions: {},
    }
  },
  created () {
  },
  computed: {
    importExcelUrl: function () {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    },
  },
  methods: {
    handleEdit1 (record) {
      this.$refs.modalForm.edit(record)
      this.$refs.modalForm.title = "回复"
      this.$refs.modalForm.disableSubmit = false
    },
    handleEdit2 (item) {
      item.shopComment = ""
      putAction("/mallBase/gmsComment/edit", item).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleEdit3 (item) {
      item.status = 1
      putAction("/mallBase/gmsComment/edit", item).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    handleEdit4 (item) {
      item.status = 0
      putAction("/mallBase/gmsComment/edit", item).then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.loadData()
        } else {
          this.$message.warning(res.message)
        }
      })
    },
    initDictConfig () {
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>